from OpenGL.arrays import vbo
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
from numpy import array
import sys, math, os
from collections import namedtuple

def init(width, height):
   """ Initialize an OpenGL windown and rendering context"""
   glClearColor(0.0, 0.0, 0.0, 0.0)         #background color
   glMatrixMode(GL_PROJECTION)              #switch to projection matrix
   glLoadIdentity()                         #set to 1
   gluOrtho2D(-10., 10., -10., 10.)
   glMatrixMode(GL_MODELVIEW)               #switch to modelview matrix
   
def display():
   """Rendering einstellungen"""
   glClear(GL_COLOR_BUFFER_BIT ) # resettet angegebenen Buffer
   #glLoadIdentity() # Modelview Matrix resetten
   
   glColor3f(0., 0., 1.)
   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
   glBegin(GL_TRIANGLES) # Zeichenart einstellen
   glVertex2f(-8, -4) # Koordinaten verwenden keine Pixel
   glVertex2f(-4, 0)
   glVertex2f(-0, -4)
   glEnd()

   glFlush()
 
def reshape():
   pass
   
def main():
   width, height = 500, 500
   glutInit(sys.argv)
   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB )   
   glutInitWindowSize(width, height)
   glutCreateWindow("Test OPENGL Fensterchen")
   glutDisplayFunc(display)     #register display function

   
   # Hack for Mac OS X
#   cwd = os.getcwd()
#   glutInit(sys.argv)
#   os.chdir(cwd)

   init(width, height)#initialize OpenGL state and opengl context
   glutMainLoop()   #start even processing

if __name__ == "__main__":
   main()
